package com.example.spinning.service;

import com.example.spinning.bean.MaterialOutStock;
import com.example.spinning.mapper.MaterialOutStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MaterialOutStockService {

    @Autowired
    private MaterialOutStockMapper materialOutStockMapper;

    //得到入库单信息
    //带有分页功能的展现数据
    public List<MaterialOutStock> getAllMaterialOutStock(Integer page, Integer count) {
        int start = (page - 1) * count;
        return materialOutStockMapper.getMaterialOutStock(start,count);
    }

    //找到行数
    public int getMaterialOutStockCount() {
        return materialOutStockMapper.getCountMaterialOutStock();
    }

    //根据条件找到行数
    public int getMaterialOutStockCountByCondition(String unit,String date,String name,String purpose) {
        return materialOutStockMapper.getCountMaterialOutStockByCondition(unit,date,name,purpose);
    }

    //根据id查询入库单信息
    public MaterialOutStock getMaterialOutStockById(long id){
        MaterialOutStock stock = materialOutStockMapper.getMaterialOutStockById(id);
        return stock;
    }

    //根据条件模糊查询
    public List<MaterialOutStock> getMaterialOutStockByCondition(Integer page, Integer count, String unit, String date, String name, String purpose){
        int start = (page - 1) * count;
        return materialOutStockMapper.getMaterialOutStockByCondition(start,count,unit,date,name,purpose);
    }

    //添加入库单信息
    public int addMaterialOutStock(MaterialOutStock stock){
        return materialOutStockMapper.addMaterialOutStock(stock);
    }


    //修改
    public int updateMaterialOutStock(MaterialOutStock stock){
        return materialOutStockMapper.updateMaterialOutStockById(stock);
    }

    //删除
    public boolean deleteMaterialOutStockByIds(String ids){
        String[] split = ids.split(",");
        int result = materialOutStockMapper.delMaterialOutStockById(split);
        return result == split.length;
    }


}
